﻿
@{
    Layout = "~/Views/Shared/_AddEdit.cshtml";
}
@section header{
    <script type="text/javascript">
        function SaveBeforeCallBack() {
            var myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;

            if ($("#_ActivityName").val() == '') {
                layer.msg('温馨提示：必须填写活动名称~！~');
                $("#_ActivityName").focus();
                return true;
            }
            if ($("#_ChargeName").val() == '') {
                layer.msg('温馨提示：必须填写负责人~！~');
                $("#_ChargeName").focus();
                return true;
            }
            console.log($("#_Actstart").val() < $("#_Actend").val())
            if ($("#_Actstart").val() == '') {
                layer.msg('温馨提示：必须填写活动开始日期~！~');
                $("#_Actstart").focus();
                return true;
            }
            if ($("#_Actend").val() == '') {
                layer.msg('温馨提示：必须填写活动结束日期~！~');
                $("#_Actend").focus();
                return true;
            }
            if ($("#_Actstart").val() > $("#_Actend").val()) {
                layer.msg('温馨提示：活动结束日期不能小于开始日期~！~');
                $("#_Actstart").focus();
                return true;
            }

            if ($("#Ssui").val() == '' || $("#Ssui").val() < 1 || $("#Syue").val() == '' || $("#Syue").val() < 1) {
                layer.msg('温馨提示：必须填写开始岁数并大于1~！~');
                $("#Ssui").focus();
                return true;
            }
            else {
                Ssum = (parseInt($("#Ssui").val()) * 12) + parseInt($("#Syue").val());
                $("#_MonthStart").val(Ssum)
            }


            if ($("#Esui").val() == '' || $("#Esui").val() < 1 && $("#Eyue").val() == '' || $("#Eyue").val() < 1) {
                layer.msg('温馨提示：必须填写结束岁数并大于1~！~'); return true;
            }
            else {
                Esum = (parseInt($("#Esui").val()) * 12) + parseInt($("#Eyue").val());
                $("#_MonthEnd").val(Esum)
            }


            if (Ssum > Esum) {
                layer.msg('温馨提示：必须开始年龄不能大于结束年龄~！~');
                $("#Ssui").focus();
                return true;
            }
            if ($("#_ActAddress").val() == '') {
                layer.msg('温馨提示：必须填写活动地址~！~');
                $("#_ActAddress").focus();
                return true;
            }
            if ($("#_EndSign").val() == '' || ($("#_EndSign").val() < $("#_Actstart").val())) {
                layer.msg('温馨提示：必须填写截止报名日期并不能小于活动开始日期~！~');
                $("#_EndSign").focus();
                return true;
            }
            if ($('#xingzhi1').is(':checked')) {

                if ($("#_MPrice").val() != '' || $("#_Classhour").val() != '') {
                }
                else {
                    layer.msg('温馨提示：必须填写会员价或课时~！~');
                    $("#_MPrice").focus();
                    return true;
                }
                if ($("#_NoMPrice").val() == '') {

                    layer.msg('温馨提示：必须填写非会员价~！~');
                    $("#_NoMPrice").focus();
                    return true;
                }
            }
            if ($("#_tel").val() == '' || !myreg.test($("#_tel").val())) {
                layer.msg('温馨提示：必须填写正确的联系方式~！~');
                $("#_tel").focus();
                return true;
            }
        }
    </script>
}

@*<input type="hidden" name="_Createdate" id="_Createdate" value="@ViewBag.data["Createdate"]" />
    <input type="hidden" name="_LeagueId" id="_LeagueId" value="@ViewBag.data["LeagueId"]" />
    <input type="hidden" id="_IsClassHour" name="_IsClassHour" value="@ViewBag.data["IsClassHour"]">
    <input type="hidden" id="_IsAll" name="_IsAll" value="@ViewBag.data["IsAll"]">
    <input type="hidden" id="_Courses" name="_Courses" value="@ViewBag.data["Courses"]">*@
<style>
    .layui-form-label {
        float: left;
        display: block;
        padding: 9px 15px;
        width: 80px;
        font-weight: 400;
        line-height: 20px;
        /* text-align: right; */
    }
</style>
<input type="hidden" id="_used" name="_used" value="@ViewBag.data["used"]">
<input type="hidden" id="_ActType" name="_ActType" value="@ViewBag.data["ActType"]">
<input type="hidden" id="_MonthStart" name="_MonthStart" value="@ViewBag.data["MonthStart"]">
<input type="hidden" id="_MonthEnd" name="_MonthEnd" value="@ViewBag.data["MonthEnd"]">
<input type="hidden" name="_Createdate" id="_Createdate" value="@ViewBag.data["Createdate"]" />
<input type="hidden" name="_LeagueId" id="_LeagueId" value="@ViewBag.data["LeagueId"]" />
<input type="hidden" name="_state" id="_state" value="@ViewBag.data["state"]" />
<input type="hidden" name="_chargeId" id="_chargeId" value="@ViewBag.data["chargeId"]" />
<input type="hidden" name="_ImageUrl" id="_ImageUrl" value="@ViewBag.data["ImageUrl"]" />
<input type="hidden" name="_ImageName" id="_ImageName" value="@ViewBag.data["ImageName"]" />
<div class="layui-col-md12">
    <div style="margin-top:2rem">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><span style="color:red">*</span><span style="margin-left:0.5rem">活动名称</span></label>
                <div class="layui-input-inline">
                    <input type="text" id="_ActivityName" name="_ActivityName" required lay-verify="required" placeholder="请输入活动名称" autocomplete="off" class="layui-input" value="@ViewBag.data["ActivityName"]">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><span style="color:red">*</span><span style="margin-left:0.5rem">负责人</span></label>
                <div class="layui-input-inline">
                    <input type="text" id="_ChargeName" name="_ChargeName" required lay-verify="required" placeholder="请输入负责人" autocomplete="off" class="layui-input" value="@ViewBag.data["ChargeName"]">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><span style="color:red">*</span><span style="margin-left:0.5rem">活动时间</span></label>
                <div class="layui-input-inline" style="width: 12rem;">
                    <input type="text" name="_Actstart" id="_Actstart" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input test-laydate-item" value="@ViewBag.data["Actstart"]">
                </div>
                <div class="layui-form-mid">-</div>
                <div class="layui-input-inline" style="width: 12rem;">
                    <input type="text" name="_Actend" id="_Actend" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input test-laydate-item" value="@ViewBag.data["Actend"]">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span><span style="margin-left:0.5rem">起始年龄</span></label>
            <div class="layui-input-inline">
                <input type="number" id="Ssui" placeholder="请输入多少岁" class="layui-input" style="width:10rem">
            </div>
            <div class="layui-form-mid layui-word-aux">岁</div>
            <div class="layui-input-inline">
                <input type="number" id="Syue" placeholder="请输入月" class="layui-input" style="width:10rem">
            </div>
            <div class="layui-form-mid layui-word-aux">月</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span><span style="margin-left:0.5rem">终止年龄</span></label>
            <div class="layui-input-inline">
                <input type="number" id="Esui" placeholder="请输入多少岁" class="layui-input" style="width:10rem">
            </div>
            <div class="layui-form-mid layui-word-aux">岁</div>
            <div class="layui-input-inline">
                <input type="number" id="Eyue" placeholder="请输入月" class="layui-input" style="width:10rem">
            </div>
            <div class="layui-form-mid layui-word-aux">月</div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span style="color:red">*</span><span style="margin-left:0.5rem">活动地址</span></label>
            <div class="layui-input-block">
                <input type="text" id="_ActAddress" name="_ActAddress" required lay-verify="required" placeholder="请输入地址" autocomplete="off" class="layui-input" value="@ViewBag.data["ActAddress"]">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><span style="color:red">*</span><span style="margin-left:0.5rem">截止报名</span></label>
                <div class="layui-input-inline">
                    <input type="text" name="_EndSign" id="_EndSign" lay-verify="date" placeholder="输入日期" autocomplete="off" class="layui-input" value="@ViewBag.data["EndSign"]">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">活动费用</label>
            <div class="layui-input-inline">
                <input type="radio" id="xingzhi0" name="leixing" value="0" title="免费" lay-skin="switch" lay-filter="ActType0" @(ViewBag.data["ActType"] == 0 ? "checked='checked'" : "")>
                <input type="radio" id="xingzhi1" name="leixing" value="1" title="收费" lay-skin="switch" lay-filter="ActType1" @(ViewBag.data["ActType"] == 1 ? "checked='checked'" : "")>
            </div>
        </div>
        <div id="shoufei" style="display:none">
            <div class="layui-form-item">
                <label class="layui-form-label" id="ContType"><span style="color:red">*</span><span style="margin-left:0.5rem">会员价:</span></label>
                <div class="layui-input-inline">
                    <input type="text" id="_MPrice" name="_MPrice" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" value="@ViewBag.data["MPrice"]">
                </div>
                <div class="layui-form-mid ">元,或</div>
                <div class="layui-input-inline">
                    <input type="number" id="_Classhour" name="_Classhour" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" value="@ViewBag.data["Classhour"]">
                </div>
                <label class="layui-form-label" style="text-align:left">课时</label>
            </div>
            <div class="layui-form-item" id="ContType1">
                <label class="layui-form-label"><span style="color:red">*</span><span style="margin-left:0.5rem">非会员价</span></label>
                <div class="layui-input-inline">
                    <input type="text" id="_NoMPrice" name="_NoMPrice" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" value="@ViewBag.data["NoMPrice"]">
                </div>
                <label class="layui-form-label" style="text-align:left">元</label>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">人数上限</label>
            <div class="layui-input-inline">
                <input type="number" id="_SignNumber" name="_SignNumber" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" value="@ViewBag.data["SignNumber"]">
            </div>
            <div class="layui-form-mid layui-word-aux">填0或不填表示不限制人数</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span><span style="margin-left:0.5rem">联系方式</span></label>
            <div class="layui-input-inline">
                <input type="tel" id="_tel" name="_tel" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input" value="@ViewBag.data["tel"]">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">活动备注</label>
            <div class="layui-input-block">

                <textarea name="_Remark" id="_Remark" placeholder="请输入内容" class="layui-textarea" style="min-height:100px;min-width:300px;width:20rem">@ViewBag.data["Remark"]</textarea>
            </div>
        </div>

        <div class="layui-form-item" style="margin-left:30px;">
            <div class="layui-upload">
                <button type="button" class="layui-btn layui-btn-normal" id="testList">选择附件</button>
                <div class="layui-upload-list">
                    <table class="layui-table" lay-filter="Imagetable" id="Imagetable">
                        <thead>
                        <th>文件名</th>
                        <th>大小</th>
                        <th>状态</th>
                        <th>操作</th>
                        </thead>
                        <tbody id="demoList"></tbody>
                    </table>
                </div>
                <button type="button" class="layui-btn" id="testListAction">开始上传</button>
            </div>
        </div>
        @if (@ViewBag.Lx == 1)
        {
            <div class="layui-form-item" style="margin-left:30px;" id="file">
                <div class="layui-upload">
                    <h3>预览列表</h3>
                    <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                        <div class="layui-form">
                            <table class="layui-table">
                                <thead>
                                    <tr>
                                        <th>文件名</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <template v-if="fileList">

                                        <tr v-for="(item,index) in fileList">
                                            <td>{{item.Name}}</td>
                                            <td>
                                                <a class='layui-btn layui-bg-green layui-btn-xs' v-on:click="dowloadFile(item.Name,item.Url)">下载</a>
                                                <a class='layui-btn layui-bg-red layui-btn-xs' v-on:click="delFile(item.id,item.Name,item.Url)" v-bind:id="item.id">删除</a>
                                            </td>
                                        </tr>
                                    </template>
                                </tbody>
                            </table>
                        </div>
                    </blockquote>
                </div>
            </div>
        }
    </div>
</div>
<script type="text/javascript" src="../Htc/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="../Htc/vue.min.js"></script>
<script type="text/javascript" src="../Layui/layui.js"></script>
<script>
c
</script>
<script>
        $(function () {
            if (@ViewBag.data["ActType"]== 1) {
                $("#shoufei").show();
            }
            else if (@ViewBag.data["ActType"]== 0) {
                $("#shoufei").hide();
            }
    });

    layui.use('form', function () {
        var form = layui.form;
        //各种基于事件的操作，下面会有进一步介绍
        //监听指定开关
        form.on('radio(ActType1)', function (data) {
            if (this.checked) {
                $("#shoufei").show();
                $("#_ActType").val("1");
            }
            else {
            }
        });
        //监听指定开关
        form.on('radio(ActType0)', function (data) {
            if (this.checked) {
                $("#shoufei").hide();
                $("#_ActType").val("0");
            }
            else {
            }
        });

        layui.use('upload', function () {
            var upload = layui.upload;

            ///多文件列表示例
            var demoListView = $('#demoList')
                , uploadListIns = upload.render({
                    elem: '#testList'
                    , url: '../Activitys/Activity/Upload?DirName=activity'
                    , accept: 'file'
                    , multiple: true
                    , auto: false
                    , bindAction: '#testListAction'
                    , choose: function (obj) {
                        var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
                        //读取本地文件
                        obj.preview(function (index, file, result) {
                            var tr = $(['<tr id="upload-' + index + '">'
                                , '<td>' + file.name + '</td>'
                                , '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>'
                                , '<td>等待上传</td>'
                                , '<td>'
                                , '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
                                , '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                                , '</td>'
                                , '</tr>'].join(''));

                            var ext, idx;
                               idx = file.name.lastIndexOf(".");
                            if (idx != -1) {
                                ext = file.name.substr(idx + 1).toUpperCase();
                                ext = ext.toLowerCase();
                                // alert("ext="+ext);
                                if (ext != 'jpg' && ext != 'png' && ext != 'jpeg' && ext != 'gif' && ext != 'xls' && ext != 'xlsx') {
                                    layer.msg('只能上传.jpg  .png  .jpeg  .gif.xls.xlsx类型的文件~！');
                                    return;
                                }
                            } else {
                                layer.msg('只能上传.jpg  .png  .jpeg  .gif.xls.xlsx类型的文件~！');
                                return;
                            }

                            //单个重传
                            tr.find('.demo-reload').on('click', function () {
                                obj.upload(index, file);
                            });

                            //删除
                            tr.find('.demo-delete').on('click', function () {
                                delete files[index]; //删除对应的文件
                                tr.remove();
                                uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                            });

                            demoListView.append(tr);
                        });
                    }
                    , done: function (res, index, upload) {
                        if (res.code == 0) { //上传成功
                            var tr = demoListView.find('tr#upload-' + index)
                                , tds = tr.children();
                            tds.eq(2).html('<span style="color: #5FB878;">上传成功</span>');
                            tds.eq(3).html(''); //清空操作
                            if ($("#_ImageUrl").val() == "") {
                                $("#_ImageUrl").val(res.data.src);
                                $("#_ImageName").val(tds.eq(0).html());
                            }
                            else {
                                $("#_ImageUrl").val($("#_ImageUrl").val() + ',' + res.data.src);
                                $("#_ImageName").val($("#_ImageName").val() + ',' + tds.eq(0).html());
                            }
                            return delete this.files[index]; //删除文件队列已经上传成功的文件
                        }
                        this.error(index, upload);
                    }
                    , error: function (index, upload) {
                        var tr = demoListView.find('tr#upload-' + index)
                            , tds = tr.children();
                        tds.eq(2).html('<span style="color: #FF5722;">上传失败</span>');
                        tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
                    }
                });
        });
    })
      var vm = new Vue({
            el: '#file',
          data: {
              fileList: new Array()
            },
          created: function () {
              this.loadInfo();
            },
          methods: {
              loadInfo: function (ImageUrl, ImageName) {
                  var Url, Name, Urls, Names;
                  if (ImageUrl) {
                      Url=ImageUrl;
                  }
                  else
                      Url=$("#_ImageUrl").val();
                  if (ImageName) {
                      Name = ImageName;
                  }
                  else
                      Name = $("#_ImageName").val();

                 Urls = Url.split(",");
                 Names = Name.split(",");
                  if (Url != "") {
                      this.fileList.length = 0;
                for (var i = 0; i < Urls.length; i++) {
                    this.fileList.push({ "id": "" + (i+1)+ "","Url": "" + Urls[i] + "", "Name": "" + Names[i] + "" })
                      }
                  }
                  console.log(this.fileList)
              },
              delFile: function (id,ImageName, ImageUrl) {
               var Url =$("#_ImageUrl").val();
                  var Name = $("#_ImageName").val();
                  var length = this.fileList.length;
                  if (id == length) {
                      if (length == 1) {
                          this.fileList.length = 0;
                          this.$set(this.fileList)
                          return;
                      }
                          $("#_ImageUrl").val(Url.replace("," + ImageUrl, ""));
                          $("#_ImageName").val(Name.replace("," + ImageName, ""));
                          console.log(Name.replace(ImageName, ""))
                          this.loadInfo(Url.replace("," + ImageUrl, ""), Name.replace("," + ImageName, ""));
                      }
                      else {
                          $("#_ImageUrl").val(Url.replace(ImageUrl + ",", ""));
                          $("#_ImageName").val(Name.replace(ImageName + ",", ""));
                          console.log(Name.replace(ImageName + ",", ""))
                          this.loadInfo(Url.replace(ImageUrl + ",", ""), Name.replace(ImageName + ",", ""));
                  }
                  layer.msg("删除成功！");
              },
              dowloadFile: function (ImageName, ImageUrl) {
                  var url = "../../UpFile/activity" + ImageUrl;
                  window.open("../Activitys/Activity/DownFile?fileName=" + ImageUrl.substr(ImageUrl.indexOf('/') + 1, ImageUrl.length) + "&filePath=" + url);
              }
          }
        })
</script>

@section fooler{
    <script>
    if (@ViewBag.Lx== 1)//编辑状态赋值数据。岁月数据，字段名一致就可以自动赋值。不一致要自己转换，.Lx==1表示编辑状态
    {

            @*if ("@ViewBag.data["ImageUrl"]" != ""&&"@ViewBag.data["ImageName"]" != "") {
                var url = "@ViewBag.data["ImageUrl"]";
                var name = "@ViewBag.data["ImageName"]";
                var urls = url.split(",");
                var names = name.split(",");
                for (var i = 0; i < urls.length;i++)
                $('#demo2').append(
                //'<img src="../UpFile/contract' + Images[i] + '" alt="#" width="200px" height="150px" class="layui-upload-img"> '
                    '<td>' + Images[i].names+'</td>'
               )
        }*@

        var MonthStart =@ViewBag.data["MonthStart"];
        var MonthEnd =@ViewBag.data["MonthEnd"];
        var Actstart = '@ViewBag.data["Actstart"]';
        var Actend = '@ViewBag.data["Actend"]';
        var EndSign = '@ViewBag.data["EndSign"]';
        console.log(Actstart)
        if (Actstart) {
            var time1 = Actstart.substr(0, 10);
            $("#_Actstart").val(time1);
        }
        if (Actend) {
            var time1 = Actend.substr(0, 10);
            $("#_Actend").val(time1);
        }
        if (EndSign) {
            var time1 = EndSign.substr(0, 10);
            $("#_EndSign").val(time1);
        }

        if (MonthStart) {
            $("#Ssui").val(parseInt(MonthStart / 12));
            $("#Syue").val(parseInt(MonthStart % 12));
        }
        if (MonthEnd) {
            $("#Esui").val(parseInt(MonthEnd / 12));
            $("#Eyue").val(parseInt(MonthEnd % 12));
        }
    }
    </script>
}

